/**
 * 广告API
 * @author gongph
 */

import request from '@/utils/request'
import qs from 'qs'

/**
 * 分页获取广告列表
 */
export function getADs (query) {
  return request({
    url: '/ad/list',
    params: query
  })
}

/**
 * 添加广告
 */
export function addAD (formData) {
  return request({
    url: '/ad',
    method: 'POST',
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
    data: formData
  })
}

/**
 * 修改广告
 */
export function updateAD (formData) {
  const id = formData.get('id')
  formData.delete('id')
  return request({
    url: `/ad/${id}`,
    method: 'PUT',
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
    data: formData
  })
}

/**
 * 置顶广告
 */
export function setAdTop (id, formData) {
  return request({
    url: `/ad/${id}`,
    method: 'PUT',
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
    data: formData
  })
}

/**
 * 显示与隐藏
 */
export function setAdDisplay (id, formData) {
  return request({
    url: `/ad/${id}`,
    method: 'PUT',
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
    data: formData
  })
}

/**
 * 删除广告
 */
export function deleteAD (id) {
  return request({
    url: `/ad/${id}`,
    method: 'DELETE'
  })
}
